import os
import sys
from flask import Flask
from flask_login import LoginManager

from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

if sys.platform.startswith('win'):
    prefix = 'sqlite:///'
else:
    prefix = 'sqlite:////'

db_path = os.getenv('db_path', os.path.join(app.root_path, 'data.db'))

app.config['SQLALCHEMY_DATABASE_URI'] = prefix + db_path
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# 设置签名密钥(生成环境使用环境变量配置)
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', 'dev')
db = SQLAlchemy(app)


login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'to_login'
login_manager.login_message = '暂无权限访问, 请先登录'

from app import modles, install
from app.view import *

install.start(db_path)
